#!/usr/bin/env python
# a bar plot with errorbars
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import *

N = 3 # This has to be the number of elements in the tuples ... eg: 3

#1st: TERRIBLE TERRIBLE
NoTableNoGPU = (31.441296,31.438758,32.130533)
NoTableNoGPUStd =   (0.189561,0.194033,0.196381)

# 2ND: plank not optimized
PlankNoO3 = (205.696032,205.572870,167.890715)
PlankNo03Std =   (1.183788,1.266586,1.144554)

# 3rd: Plank on GPU
PlankGPU = (648.628225,649.250284,554.229173)
PlankGPUStd =   (1.921704,2.124240,1.82169)

# Plank Regular (no GPU)
Plank = (944.923824,937.215513,571.388904)
PlankStd =   (6.049215,6.135694,3.677749)

# No Tables, with GPU
TablesGPU = (260.353264,260.727423,252.906668)
TablesGPUStd = (2.411251,2.679839,2.564723)

ind = np.arange(N)  # the x locations for the groups
width = 0.15       # the width of the bars

fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(ind, NoTableNoGPU, width, color='orange', yerr=NoTableNoGPUStd)
rects2 = ax.bar(ind+width, PlankNoO3, width, color='r', yerr=PlankNo03Std)
rects3 = ax.bar(ind+2*width, Plank, width, color='purple', yerr=PlankStd)
rects4 = ax.bar(ind+3*width, PlankGPU, width, color='b', yerr=PlankGPUStd)
rects5 = ax.bar(ind+4*width, TablesGPU, width, color='g', yerr=TablesGPUStd)

# add some
ax.set_ylabel('Number of Mega Multiples per Second')
ax.set_title('G8: Galois Arithmetic Speed Tests')
ax.set_xticks(ind+3*width)
ax.set_xticklabels( (' Test 0', ' Test 1', ' Test 2') )

ax.legend((rects1[0], rects2[0], rects3[0], rects4[0],rects5[0]),
          ('No Tables, No GPU','Tables, No GPU (Not Optimized)','Tables, No GPU (Planks Original Library)',
           'Tables, GPU','No Tables, GPU'),
          loc=2,borderaxespad=0.0,prop={'size':12})

plt.ylim(0,1500)

def autolabel(rects):
    # attach some text labels
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x()+rect.get_width()/2, 1.05*height, '%d'%int(height),
                ha='center', va='bottom')

plt.ylim(0,1500)

autolabel(rects1)
autolabel(rects2)
autolabel(rects3)
autolabel(rects4)
autolabel(rects5)

#plt.show()

########### w: 16 #############
NoTableNoGPU = (30.438243,30.448566,29.442353)
NoTableNoGPUStd =   (0.182409,0.173526,0.189222)

PlankNoO3 = (180.124336,179.275451,128.304876)
PlankNo03Std =   (0.934346,0.897168,0.752472)

PlankGPU = (489.767349,489.960295,434.855798)
PlankGPUStd =   (0.306026,0.468901,0.465153)

Plank = (461.924091,456.963200,416.533018)
PlankStd =   (3.357666,3.316171,2.765797)

TablesGPU = (243.697874,243.754854,243.301308)
TablesGPUStd = (2.387049,2.249885,2.550707)

fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(ind, NoTableNoGPU, width, color='orange', yerr=NoTableNoGPUStd)
rects2 = ax.bar(ind+width, PlankNoO3, width, color='r', yerr=PlankNo03Std)
rects3 = ax.bar(ind+2*width, Plank, width, color='purple', yerr=PlankStd)
rects4 = ax.bar(ind+3*width, PlankGPU, width, color='b', yerr=PlankGPUStd)
rects5 = ax.bar(ind+4*width, TablesGPU, width, color='g', yerr=TablesGPUStd)

# add some
ax.set_ylabel('Number of Mega Multiples per Second')
ax.set_title('G16: Galois Arithmetic Speed Tests')
ax.set_xticks(ind+3*width)
ax.set_xticklabels( (' Test 0', ' Test 1', ' Test 2') )

ax.legend((rects1[0], rects2[0], rects3[0], rects4[0],rects5[0]),
          ('No Tables, No GPU','Tables, No GPU (Not Optimized)','Tables, No GPU (Planks Original Library)',
           'Tables, GPU','No Tables, GPU'),
          loc=2,borderaxespad=0.0,prop={'size':12})

plt.ylim(0,800)

autolabel(rects1)
autolabel(rects2)
autolabel(rects3)
autolabel(rects4)
autolabel(rects5)

########### w: 32 #############
NoTableNoGPU = (6.090492,6.090132,5.532034)
NoTableNoGPUStd =   (0.037222,0.039140,0.034761)

PlankNoO3 = (34.754086,34.733375,34.564500)
PlankNo03Std =   (0.222153,0.223454,0.281646)

PlankGPU = (237.861899,237.720305,226.772500)
PlankGPUStd =   (1.951268,2.382447,1.910603)

Plank = (162.768848,162.668420,161.671835)
PlankStd =   (1.055990,1.130352,1.266783)

TablesGPU = (194.373764,194.379414,187.713226)
TablesGPUStd = (1.572379,1.764843,2.017209)

fig = plt.figure()
ax = fig.add_subplot(111)
rects1 = ax.bar(ind, NoTableNoGPU, width, color='orange', yerr=NoTableNoGPUStd)
rects2 = ax.bar(ind+width, PlankNoO3, width, color='r', yerr=PlankNo03Std)
rects3 = ax.bar(ind+2*width, Plank, width, color='purple', yerr=PlankStd)
rects4 = ax.bar(ind+3*width, PlankGPU, width, color='b', yerr=PlankGPUStd)
rects5 = ax.bar(ind+4*width, TablesGPU, width, color='g', yerr=TablesGPUStd)

# add some
ax.set_ylabel('Number of Mega Multiples per Second')
ax.set_title('G32: Galois Arithmetic Speed Tests')
ax.set_xticks(ind+3*width) # This centers the labels Test 0, Test 1... etc
ax.set_xticklabels( (' Test 0', ' Test 1', ' Test 2') )

ax.legend((rects1[0], rects2[0], rects3[0], rects4[0],rects5[0]),
          ('No Tables, No GPU','Tables, No GPU (Not Optimized)','Tables, No GPU (Planks Original Library)',
           'Tables, GPU','No Tables, GPU'),
          loc=2,borderaxespad=0.0,prop={'size':12})

plt.ylim(0,450)

autolabel(rects1)
autolabel(rects2)
autolabel(rects3)
autolabel(rects4)
autolabel(rects5)

plt.show()
